<%= form_for(@book, html: { class: "form-horizontal"}) do |f| %>
<% if @book.errors.any? %>
<div id="error_explanation">
	<div class="alert alert-danger">
		<p style="margin: 0px 20px"><%= t(:form_contains, ile: @book.errors.count) %> </p>
	
    	<ul>
    		<% @book.errors.full_messages.each do |msg| %>
    		<li>
    			<%= msg %>
    		</li>
    		<% end %>
    	</ul>
	</div>
</div>
<% end %>

	<div class="span6 offset3">
	    <div class="form-group">
	       <%= f.label :title, titleize(t(:title)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
                <%= f.text_field :title, class: 'form-control' %> 
           </div>
	    </div>
	    
	    <div class="form-group">
           <%= f.label :author_id, titleize(t(:author)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
               <div class="input-group" style="margin-bottom: 15px;">
                  <%= f.collection_select(:author_id, Author.all.order(:surname), :id, :surname_and_name,
                        {include_blank: true}, {class: 'form-control', style: 'padding: 7px 12px;'}) %>
                  <span class="input-group-btn">
                    <button class="btn btn-default btn-primary" data-toggle="modal" data-target="#addAuthorModal">
                       <%= titleize(t(:add_author))%>
                    </button>
                  </span>
                </div>
           </div>
        </div>
        
        <div class="form-group">
    		<%= f.label :book_category_id, titleize(t(:book_category)), class: 'col-sm-2 control-label' %>
    		<div class="col-sm-10">
    			<div class="btn-group" style="margin-bottom: 15px;  width: 100%">
    				<select id="book_category_ids" name="book_category_ids[]" multiple="multiple">
    					<%= options_for_select(@book_categories, @book.book_categories.collect {|d| d.id }) %>
    				</select>
    				<button id="add_category" class="btn btn-default btn-primary" data-toggle="modal" data-target="#add_category_modal">
    					<%= titleize(t(:add_category))%>
    				</button>
    			</div>
    		</div>
    	</div>

        <div class="form-group">
           <%= f.label :isbn, titleize(t(:isbn)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
                <%= f.text_field :isbn, class: 'form-control' %> 
           </div>
        </div>
       
        <div class="form-group">
           <%= f.label :language, titleize(t(:language)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
                <%= f.text_field :language, class: 'form-control' %> 
           </div>
        </div>
        
        <div class="form-group">
           <%= f.label :description, titleize(t(:description)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
                <%= f.text_area :description, class: 'form-control' %> 
           </div>
        </div>

        <div class="form-group">
           <%= f.label :quantity, titleize(t(:quantity)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
                <%= f.number_field :quantity, class: 'form-control' %> 
           </div>
        </div>
        
        <div class="form-group">
           <%= f.label :place, titleize(t(:place)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
                <%= f.text_field :place, class: 'form-control' %> 
           </div>
        </div>
        
        <div class="form-group">
           <%= f.label :release_date, titleize(t(:release_date)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
                <%= f.text_field :release_date, id: "release_date", class: 'form-control' %> 
           </div>
        </div>

        <div class="form-group">
           <%= f.label :pages, titleize(t(:pages)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
                <%= f.number_field :pages, class: 'form-control', hint: "Numer" %> 
           </div>
        </div>

        <div class="form-group">
           <%= f.label :photo, titleize(t(:photo)), class: 'col-sm-2 control-label' %>
           <div class="col-sm-10">
                <%= f.file_field :photo, class: 'form-control' %> 
           </div>
        </div>
        <br />
        <div class="form-group">
             <div class="col-sm-offset-2 col-sm-10">
                <%= f.submit titleize(t(:save)), class: "btn btn-primary" %>
             </div>
        </div>
        <br/>
        <div class="panel panel-default">
          <div class="panel-heading"><strong><%= titleize(t(:current_photo)) %>:</strong></div>
          <div class="panel-body">
             <%= image_tag(@book.photo, width: 600) if @book.photo.present? %>
          </div>
        </div>
	</div>
<% end %>

<!-- Modal -->
<div class="modal fade" id="addAuthorModal" tabindex="-1" role="dialog"
    aria-labelledby="add_author_dialog_lbl" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="add_author_dialog_lbl"><%=titleize(t(:add_author))%></h4>
      </div>
      <div class="modal-body">
        <label for="author_name"><%=titleize(t(:name))%></label>
        <input id="author_name" name="author[name]" type="text" class="form-control">
        <label for="author_surname"><%=titleize(t(:surname))%></label>
        <input id="author_surname" name="author[surname]" type="text" class="form-control">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="save_new_author"><%=titleize(t(:save))%></button>
        <button type="button" class="btn btn-default" data-dismiss="modal"><%=titleize(t(:close))%></button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="add_category_modal" tabindex="-1" role="dialog"
    aria-labelledby="add_category_dialog_lbl" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="add_category_dialog_lbl"><%=titleize(t(:add_category))%></h4>
      </div>
      <div class="modal-body">
        <label for="author_name"><%=titleize(t(:category_name))%></label>
        <input id="category_name" name="book_category[category_name]" type="text" class="form-control">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="save_new_category"><%=titleize(t(:save))%></button>
        <button type="button" class="btn btn-default" data-dismiss="modal"><%=titleize(t(:close))%></button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->